﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true"
    CodeFile="Nurses.aspx.cs" Inherits="Clinic.Personnel.Nurses" Title="Списък - медицински сестри" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder" runat="Server">

    <script type="text/javascript">
	function ShowWarning()
	{
		if(document.getElementsByName('generateWarning')[0] != null)
		{
			return confirm('Желаете ли да затворите формата за въвеждане? Текущите промени няма да бъдат записани');
		}
		return true;
	}
    </script>

    <asp:MultiView ID="mvNurses" runat="server">
        <asp:View ID="vNursesList" runat="server">
            <table style="border-right: #99ccff thin solid; border-top: #99ccff thin solid; border-left: #99ccff thin solid;
                border-bottom: #99ccff thin solid" width="100%">
                <tr>
                    <td colspan="6">
                        <asp:Label ID="Label1" runat="server" Font-Size="x-Large" Text="Списък медицински сестри"></asp:Label><hr />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:GridView ID="gvNurseList" runat="server" AutoGenerateColumns="False" DataKeyNames="NurseID"
                            DataSourceID="odsNurses" AllowPaging="True">
                            <Columns>
                                <asp:TemplateField HeaderText="Операции" ShowHeader="False">
                                    <EditItemTemplate>
                                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                                            Text="Обнови"></asp:LinkButton>
                                        &nbsp;<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                            Text="Прекъсни"></asp:LinkButton>
                                    </EditItemTemplate>
                                    <ItemTemplate>
                                        <asp:LinkButton ID="lbtnSelectNurse" runat="server" CausesValidation="False" CommandName="Select"
                                            Text="Детайли" OnClick="lbtnSelectNurse_Click"></asp:LinkButton>
                                        &nbsp;<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="False" OnClientClick="return confirm('Желаете ли да изтриете този запис?');"
                                            CommandName="Delete" Text="Изтрий"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="FirstName" HeaderText="Име" SortExpression="FirstName" />
                                <asp:BoundField DataField="MiddleName" HeaderText="Презиме" SortExpression="MiddleName" />
                                <asp:BoundField DataField="LastName" HeaderText="Фамилия" SortExpression="LastName" />
                                <asp:BoundField DataField="Phone" HeaderText="Телефон" SortExpression="Phone" />
                            </Columns>
                        </asp:GridView>
                        <br />
                        <asp:LinkButton ID="lbtnAddNewNurse" runat="server" OnClick="lbtnAddNewNurse_Click">Добави нов запис</asp:LinkButton>
                        <asp:SqlDataSource ID="sdsNurses" runat="server" ConnectionString="<%$ ConnectionStrings:ClinicConnectionString %>"
                            DeleteCommand="up_NursesDelete" InsertCommand="up_NursesInsert" SelectCommand="up_NursesSelect"
                            UpdateCommand="up_NursesUpdate" DeleteCommandType="StoredProcedure" InsertCommandType="StoredProcedure"
                            SelectCommandType="StoredProcedure" UpdateCommandType="StoredProcedure">
                            <DeleteParameters>
                                <asp:Parameter Name="NurseID" Type="Int32" />
                            </DeleteParameters>
                            <UpdateParameters>
                                <asp:Parameter Name="NurseID" Type="Int32" />
                                <asp:Parameter Name="FirstName" Type="String" />
                                <asp:Parameter Name="MiddleName" Type="String" />
                                <asp:Parameter Name="LastName" Type="String" />
                                <asp:Parameter Name="EGN" Type="String" />
                                <asp:Parameter Name="Address" Type="String" />
                                <asp:Parameter Name="Phone" Type="String" />
                                <asp:Parameter Name="Email" Type="String" />
                            </UpdateParameters>
                            <InsertParameters>
                                <asp:Parameter Name="NurseID" Type="Int32" />
                                <asp:Parameter Name="FirstName" Type="String" />
                                <asp:Parameter Name="MiddleName" Type="String" />
                                <asp:Parameter Name="LastName" Type="String" />
                                <asp:Parameter Name="EGN" Type="String" />
                                <asp:Parameter Name="Address" Type="String" />
                                <asp:Parameter Name="Phone" Type="String" />
                                <asp:Parameter Name="Email" Type="String" />
                            </InsertParameters>
                        </asp:SqlDataSource>
                        <asp:ObjectDataSource ID="odsNurses" runat="server" DeleteMethod="Delete" InsertMethod="Insert"
                            SelectMethod="GetNurses" TypeName="NursesDSTableAdapters.NursesTableAdapter"
                            UpdateMethod="Update">
                            <DeleteParameters>
                                <asp:Parameter Name="NurseID" Type="Int32" />
                            </DeleteParameters>
                            <UpdateParameters>
                                <asp:Parameter Name="UserId" Type="Object" />
                                <asp:Parameter Name="NurseID" Type="Int32" />
                                <asp:Parameter Name="FirstName" Type="String" />
                                <asp:Parameter Name="MiddleName" Type="String" />
                                <asp:Parameter Name="LastName" Type="String" />
                                <asp:Parameter Name="EGN" Type="String" />
                                <asp:Parameter Name="Address" Type="String" />
                                <asp:Parameter Name="Phone" Type="String" />
                                <asp:Parameter Name="Email" Type="String" />
                            </UpdateParameters>
                            <InsertParameters>
                                <asp:Parameter Name="UserId" Type="Object" />
                                <asp:Parameter Name="NurseID" Type="Int32" />
                                <asp:Parameter Name="FirstName" Type="String" />
                                <asp:Parameter Name="MiddleName" Type="String" />
                                <asp:Parameter Name="LastName" Type="String" />
                                <asp:Parameter Name="EGN" Type="String" />
                                <asp:Parameter Name="Address" Type="String" />
                                <asp:Parameter Name="Phone" Type="String" />
                                <asp:Parameter Name="Email" Type="String" />
                            </InsertParameters>
                        </asp:ObjectDataSource>
                    </td>
                </tr>
            </table>
        </asp:View>
        <asp:View ID="vNurseInfo" runat="server">
            <table style="border-right: #99ccff thin solid; border-top: #99ccff thin solid; border-left: #99ccff thin solid;
                border-bottom: #99ccff thin solid" width="100%">
                <tr>
                    <td colspan="6" style="height: 21px">
                        <asp:Label ID="Label2" runat="server" Font-Size="x-Large" Text="Информация за медицинска сестра"></asp:Label><hr />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:DetailsView ID="dvNurses" runat="server" PagerSettings-Mode="NextPrevious" AutoGenerateRows="False"
                            DataKeyNames="NurseID,UserId" DataSourceID="odsNurseDetails" Height="50px" Width="285px"
                            AllowPaging="True" OnItemDeleting="dvNurses_ItemDeleting" OnItemUpdating="dvNurses_ItemUpdating">
                            <Fields>
                                <asp:TemplateField HeaderText="Име" SortExpression="FirstName">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="tbNameEdit" runat="server" Text='<%# Bind("FirstName") %>' MaxLength="30"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="rfvNameEdit" runat="server" ControlToValidate="tbNameEdit"
                                            Display="Dynamic" ErrorMessage='Полето - "Име" е задължително!' ToolTip='Полето - "Име" е задължително!'>*</asp:RequiredFieldValidator>
                                    </EditItemTemplate>
                                    <InsertItemTemplate>
                                        <asp:TextBox ID="tbNameInsert" runat="server" Text='<%# Bind("FirstName") %>' MaxLength="30"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="rfvNameInsert" runat="server" ControlToValidate="tbNameInsert"
                                            Display="Dynamic" ErrorMessage='Полето - "Име" е задължително!' ToolTip='Полето - "Име" е задължително!'>*</asp:RequiredFieldValidator>
                                    </InsertItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="lblName" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Презиме" SortExpression="MiddleName">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="tbMiddleNameEdit" runat="server" Text='<%# Bind("MiddleName") %>'
                                            MaxLength="30"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="rfvMiddleNameEdit" runat="server" ControlToValidate="tbMiddleNameEdit"
                                            ErrorMessage='Полето - "Презме" е задължително!' ToolTip='Полето - "Презме" е задължително!'>*</asp:RequiredFieldValidator>
                                    </EditItemTemplate>
                                    <InsertItemTemplate>
                                        <asp:TextBox ID="tbMiddleNameInsert" runat="server" Text='<%# Bind("MiddleName") %>'
                                            MaxLength="30"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="rfvMiddleNameInsert" runat="server" ControlToValidate="tbMiddleNameInsert"
                                            Display="Dynamic" ErrorMessage='Полето - "Презме" е задължително!' ToolTip='Полето - "Презме" е задължително!'>*</asp:RequiredFieldValidator>
                                    </InsertItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="lblMiddleName" runat="server" Text='<%# Bind("MiddleName") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Фамилия" SortExpression="LastName">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="tbLastNameEdit" runat="server" Text='<%# Bind("LastName") %>' MaxLength="30"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="rfvFamilyEdit" runat="server" ControlToValidate="tbLastNameEdit"
                                            Display="Dynamic" ErrorMessage='Полето - "Фамилия" е задължително!' ToolTip='Полето - "Фамилия" е задължително!'>*</asp:RequiredFieldValidator>
                                    </EditItemTemplate>
                                    <InsertItemTemplate>
                                        <asp:TextBox ID="tbLastNameInsert" runat="server" Text='<%# Bind("LastName") %>'
                                            MaxLength="30"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="rfvFamilyInsert" runat="server" ControlToValidate="tbLastNameInsert"
                                            Display="Dynamic" ErrorMessage='Полето - "Фамилия" е задължително!' ToolTip='Полето - "Фамилия" е задължително!'>*</asp:RequiredFieldValidator>
                                    </InsertItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="lblLastName" runat="server" Text='<%# Bind("LastName") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="ЕГН" SortExpression="EGN">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="tbPersonalNumberEdit" runat="server" Text='<%# Bind("EGN") %>' MaxLength="20"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="rfvPersonalNumberEdit" runat="server" ControlToValidate="tbPersonalNumberEdit"
                                            Display="Dynamic" ErrorMessage='Полето - "ЕГН" е задължително!' ToolTip='Полето - "ЕГН" е задължително!'>*</asp:RequiredFieldValidator><asp:CompareValidator
                                                ID="cvPersonalNumberEdit" runat="server" ControlToValidate="tbPersonalNumberEdit"
                                                Display="Dynamic" ErrorMessage='Полето - "ЕГН" не е валидно!' Operator="DataTypeCheck"
                                                ToolTip='Полето - "ЕГН" не е валидно!' Type="Integer">*</asp:CompareValidator>
                                    </EditItemTemplate>
                                    <InsertItemTemplate>
                                        <asp:TextBox ID="tbPersonalNumberInsert" runat="server" Text='<%# Bind("EGN") %>'
                                            MaxLength="20"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="rfvPersonalNumberInsert" runat="server" ControlToValidate="tbPersonalNumberInsert"
                                            Display="Dynamic" ErrorMessage='Полето - "ЕГН" е задължително!' ToolTip='Полето - "ЕГН" е задължително!'>*</asp:RequiredFieldValidator><asp:CompareValidator
                                                ID="cvPersonalNumberInsert" runat="server" ControlToValidate="tbPersonalNumberInsert"
                                                Display="Dynamic" ErrorMessage='Полето - "ЕГН" не е валидно!' Operator="DataTypeCheck"
                                                ToolTip='Полето - "ЕГН" не е валидно!' Type="Integer">*</asp:CompareValidator>
                                    </InsertItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="lblPersonalNumber" runat="server" Text='<%# Bind("EGN") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Адрес" SortExpression="Address">
                                    <EditItemTemplate>
                                        <asp:TextBox ID="tbAddressEdit" runat="server" Text='<%# Bind("Address") %>' MaxLength="100"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="rfvAddressEdit" runat="server" ControlToValidate="tbAddressEdit"
                                            Display="Dynamic" ErrorMessage='Полето - "Адрес" е задължително!' ToolTip='Полето - "Адрес" е задължително!'>*</asp:RequiredFieldValidator>
                                    </EditItemTemplate>
                                    <InsertItemTemplate>
                                        <asp:TextBox ID="tbAddressInsert" runat="server" Text='<%# Bind("Address") %>' MaxLength="100"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="rfvAddressInsert" runat="server" ControlToValidate="tbAddressInsert"
                                            Display="Dynamic" ErrorMessage='Полето - "Адрес" е задължително!' ToolTip='Полето - "Адрес" е задължително!'>*</asp:RequiredFieldValidator>
                                    </InsertItemTemplate>
                                    <ItemTemplate>
                                        <asp:Label ID="lblAddress" runat="server" Text='<%# Bind("Address") %>'></asp:Label>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField DataField="Phone" HeaderText="Телефон" SortExpression="Phone" />
                                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                                <asp:TemplateField ShowHeader="False">
                                    <EditItemTemplate>
                                        <input type="hidden" name="generateWarning" />
                                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" CommandName="Update"
                                            Text="Обнови"></asp:LinkButton>
                                        <asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel"
                                            Text="Прекъсни"></asp:LinkButton>
                                    </EditItemTemplate>
                                    <InsertItemTemplate>
                                        <input type="hidden" name="generateWarning" />
                                        <asp:LinkButton ID="lbtnAddNurse" runat="server" CausesValidation="True" OnClick="lbtnAddNurse_Click"
                                            Text="Добави"></asp:LinkButton>
                                        <asp:LinkButton ID="lbtnCancelInsert" runat="server" CausesValidation="False" OnClick="lbtnCancelInsert_Click"
                                            Text="Прекъсни"></asp:LinkButton>
                                    </InsertItemTemplate>
                                    <ItemTemplate>
                                        <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Edit"
                                            Text="Редактирай"></asp:LinkButton>
                                        <asp:LinkButton ID="lbtnDeleteNurse" runat="server" CausesValidation="False" OnClientClick="return confirm('Желаете ли да изтриете този запис?');"
                                            OnClick="lbtnDeleteNurse_Click" Text="Изтрий"></asp:LinkButton>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Fields>
                            <FooterTemplate>
                                <br />
                                <asp:LinkButton ID="lbtnBackToList" runat="server" CausesValidation="false" OnClick="lbtnBackToList_Click"
                                    OnClientClick="javascript:return ShowWarning();">Обратно към списъка</asp:LinkButton>
                            </FooterTemplate>
                            <PagerSettings Mode="NextPrevious" />
                        </asp:DetailsView>
                        <asp:SqlDataSource ID="sdsNurseDetails" runat="server" ConnectionString="<%$ ConnectionStrings:ClinicConnectionString %>"
                            SelectCommand="up_NursesSelectById" DeleteCommand="up_NursesDelete" DeleteCommandType="StoredProcedure"
                            InsertCommand="up_NursesInsert" InsertCommandType="StoredProcedure" SelectCommandType="StoredProcedure"
                            UpdateCommand="up_NursesUpdate" UpdateCommandType="StoredProcedure">
                            <SelectParameters>
                                <asp:ControlParameter ControlID="gvNurseList" Name="NurseID" PropertyName="SelectedValue" />
                            </SelectParameters>
                            <DeleteParameters>
                                <asp:Parameter Name="NurseID" Type="Int32" />
                            </DeleteParameters>
                            <UpdateParameters>
                                <asp:Parameter Name="NurseID" Type="Int32" />
                                <asp:Parameter Name="FirstName" Type="String" />
                                <asp:Parameter Name="MiddleName" Type="String" />
                                <asp:Parameter Name="LastName" Type="String" />
                                <asp:Parameter Name="EGN" Type="String" />
                                <asp:Parameter Name="Address" Type="String" />
                                <asp:Parameter Name="Phone" Type="String" />
                                <asp:Parameter Name="Email" Type="String" />
                            </UpdateParameters>
                            <InsertParameters>
                                <asp:Parameter Name="NurseID" Type="Int32" />
                                <asp:Parameter Name="FirstName" Type="String" />
                                <asp:Parameter Name="MiddleName" Type="String" />
                                <asp:Parameter Name="LastName" Type="String" />
                                <asp:Parameter Name="EGN" Type="String" />
                                <asp:Parameter Name="Address" Type="String" />
                                <asp:Parameter Name="Phone" Type="String" />
                                <asp:Parameter Name="Email" Type="String" />
                            </InsertParameters>
                        </asp:SqlDataSource>
                        <asp:ObjectDataSource ID="odsNurseDetails" runat="server" DeleteMethod="Delete" InsertMethod="Insert"
                            SelectMethod="GetByNurseId" TypeName="NursesDSTableAdapters.NursesTableAdapter"
                            UpdateMethod="Update">
                            <DeleteParameters>
                                <asp:Parameter Name="NurseID" Type="Int32" />
                            </DeleteParameters>
                            <UpdateParameters>
                                <asp:Parameter Name="UserId" Type="Object" />
                                <asp:Parameter Name="NurseID" Type="Int32" />
                                <asp:Parameter Name="FirstName" Type="String" />
                                <asp:Parameter Name="MiddleName" Type="String" />
                                <asp:Parameter Name="LastName" Type="String" />
                                <asp:Parameter Name="EGN" Type="String" />
                                <asp:Parameter Name="Address" Type="String" />
                                <asp:Parameter Name="Phone" Type="String" />
                                <asp:Parameter Name="Email" Type="String" />
                            </UpdateParameters>
                            <SelectParameters>
                                <asp:ControlParameter ControlID="gvNurseList" Name="NurseID" PropertyName="SelectedValue"
                                    Type="Int32" />
                            </SelectParameters>
                            <InsertParameters>
                                <asp:Parameter Name="UserId" Type="Object" />
                                <asp:Parameter Name="NurseID" Type="Int32" />
                                <asp:Parameter Name="FirstName" Type="String" />
                                <asp:Parameter Name="MiddleName" Type="String" />
                                <asp:Parameter Name="LastName" Type="String" />
                                <asp:Parameter Name="EGN" Type="String" />
                                <asp:Parameter Name="Address" Type="String" />
                                <asp:Parameter Name="Phone" Type="String" />
                                <asp:Parameter Name="Email" Type="String" />
                            </InsertParameters>
                        </asp:ObjectDataSource>
                    </td>
                </tr>
            </table>
        </asp:View>
    </asp:MultiView>&nbsp;<br />
    <br />
    <br />
</asp:Content>
